package com.example.dqnm.controller;

import com.example.dqnm.pojo.Comments;
import com.example.dqnm.pojo.CommentsQuery;
import com.example.dqnm.pojo.ajaxResult;
import com.example.dqnm.service.commentService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("/comment")
public class commentController {
    @Autowired
    private commentService commentService;


    /*新增评论*/
    @PostMapping("/add")
    public ajaxResult<Boolean> addComments(@RequestBody Comments comment){
        System.out.println(comment);
        Boolean b = commentService.addComments(comment);
        return new ajaxResult<>(b);
    }

    @GetMapping("/queryComments")
    public ajaxResult<List<Comments>> queryComments(CommentsQuery commentsQuery) {
        List<Comments> commentsByQuery = commentService.findCommentsByQuery(commentsQuery);
        return new ajaxResult<>(commentsByQuery);
    }
}
